package com.controller.library;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.*;

import com.action.library.SLoginAction;
import com.bean.library.Student;

public class SLoginServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void service(HttpServletRequest request,HttpServletResponse response){
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String studentId = request.getParameter("student_id");
		String password = request.getParameter("password");
		/*******************之后用到******************/
		SLoginAction sLoginAction = new SLoginAction();
		Student student = sLoginAction.studentLogin(studentId, password);
		if(student!=null){
			request.getSession().setAttribute("student", student);
			try {
				response.sendRedirect("/Exam1/student/page/welcome.jsp");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		else{
			try {
				response.sendRedirect("/Exam1/student/page/login_incorrect.htm");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		/******************************************/
	}

}
